import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let userInfo = localStorage.getItem("miyou_userInfo") ? JSON.parse(localStorage.getItem("miyou_userInfo")):{}
if(userInfo.startTime + 30*60*1000 < Date.now()){
  // 超过了半个小时  我们要清空对应的local
  localStorage.removeItem('miyou_userInfo')
}
export default new Vuex.Store({
  state: {
    userInfo:userInfo,
    cartList:[]
  },
  mutations: {
    changeUserInfo(state,option){
      option.startTime = Date.now()
      localStorage.setItem('miyou_userInfo',JSON.stringify(option))
      state.userInfo = option
    },
    addCart(state,option){
      state.cartList.push(option)
    }
  },
  actions: {
  },
  getters:{
    name(state){
      return state.userInfo.name + '先生'
    }
  },
  modules: {
  }
})
